package com.ibeeking.found.org.cp.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.common.utils.UserUtils;
import com.ibeeking.found.org.cp.rest.service.IEmployeeService;
import com.ibeeking.found.org.service.common.param.EmployeeParam;
import com.ibeeking.found.org.service.common.param.QrCodeParam;
import com.ibeeking.found.org.service.common.query.EmployeePageQuery;
import com.ibeeking.found.org.service.common.query.EmployeeQuery;
import com.ibeeking.found.org.service.common.vo.EmployeeStatusVO;
import com.ibeeking.found.org.service.common.vo.EmployeeVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName EmployeeController
 * @Description
 * @Author ibeeking
 * @Date 2021-01-29 14:48
 **/
@RestController
@RequestMapping("/cp/employee/v1")
public class EmployeeController {

    @Resource
    private IEmployeeService employeeServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "员工列表")
    @GetMapping(value = "/list")
    public List<EmployeeVO> list(@RequestBody EmployeeQuery query) {
        return employeeServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "员工分页列表")
    @GetMapping(value = "/pageList")
    public Page<EmployeeVO> pageList(@RequestBody EmployeePageQuery pageQuery) {
        return employeeServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "员工添加")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) EmployeeParam param) {
        return employeeServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "员工修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) EmployeeParam param) {
        return employeeServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "员工查看")
    @GetMapping(value = "/view/{id}")
    public EmployeeVO view(@PathVariable("id") Long id) {
        return employeeServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "员工状态修改")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return employeeServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "员工删除")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return employeeServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "员工码查询")
    @PostMapping(value = "/qrcode")
    public void memberQrCode(@LoginUser CurrentUser currentUser, HttpServletResponse response, @RequestBody QrCodeParam param) {
        employeeServiceImpl.employeeQrCode(currentUser.getId(), response, param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "员工信息修改")
    @PostMapping(value = "/infoModify")
    public Boolean infoModify(@RequestBody @Validated EmployeeParam param) {
        param.setId(UserUtils.getUserId());
        return employeeServiceImpl.infoModify(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "员工在职状态列表")
    @PostMapping(value = "/employeeStatusList")
    public List<EmployeeStatusVO> application() {
        return employeeServiceImpl.employeeStatusList();
    }

}